using System;
using System.Collections.Generic;
using System.Linq;
using Provausio.Common.Objects;
using TrainingManagement.api.Models.BusinessObjects;
using TrainingManagement.api.Models.Data.CRUD;
using TrainingManagement.api.Models.Data.CRUD.Position;

namespace TrainingManagement.api.Models.BusinessLogic.Position
{
    public class PositionSkillSetItemInsertOperation : BusinessOperation<List<PositionSkillSetDto>, BusinessObjects.Position>
    {
        readonly PositionSkillSetInsertDataSource _skillSetInsert = new PositionSkillSetInsertDataSource();
        readonly PositionSelectOperation _positionSelect = new PositionSelectOperation();

        public override BusinessObjects.Position Run(List<PositionSkillSetDto> input)
        {
            if (_skillSetInsert.Execute(input))
            {
                return _positionSelect.Run(input[0].PositionId, true).FirstOrDefault();
            }

            throw new Exception("Save position skill sets failed.");
        }
    }
}